package org.example.controller;

import org.example.common.LoginException;
import org.example.common.R;
import org.example.common.Token;
import org.example.entity.vo.LoginVo;
import org.example.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class LoginController{
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo){

            Token token=loginService.ssLogin(loginVo);
            return R.ok(token);

    }

//    @PostMapping("/login")
//    public R login(@RequestBody LoginVo loginVo){
//        try {
//            UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(loginVo.getUsername(),loginVo.getPassword());
//            SecurityUtils.getSubject().login(usernamePasswordToken);
//        } catch (Exception e) {
//            return R.err(e.getMessage());
//        }
//        return R.ok();
//    }




    @GetMapping("/logout")
    public R logout(@RequestHeader String token){
        loginService.logout(token);
        return R.ok();
    }
}
